package com.shop.member.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.shop.member.service.MemberDeliverService;
import com.shop.member.vo.MemberVO;


/**
 * 배송정보 
 * @author geryon
 *
 */
@Controller
@RequestMapping("/MEMBER/deliver")
public class MemberDeliverController {

	private final static int LIST_ROW_CNT = 20; // 게시물 리스트 갯수
	
	@Autowired
	private MemberDeliverService service;

	/**
	 * 배송정보 리스트 페이지 호출
	 * 리스트 화면을 호출한다
	 * @return
	 */
	@RequestMapping(method = RequestMethod.POST, value="/")
	public String requestScreen(Model model) {
		return "member/deliver_list";
	}

	/**
	 * 배송정보 리스트
	 * @param model
	 * @param member
	 * @return
	 */
	@RequestMapping(method = RequestMethod.POST, value="/list")
	public Model listDeliver(Model model) {
		List<MemberVO.MemberDeliver> list = service.listDeliver();
		model.addAttribute("MODEL", list);
		return model;
	}
	
	/**
	 * 배송정보 등록
	 * @param model
	 * @param member
	 * @return
	 */
	@RequestMapping(method = RequestMethod.POST, value="/add")
	public Model addDeliver(Model model,
							@RequestBody MemberVO.MemberDeliver deliverItem) {
		service.addDeliver(deliverItem);
		return model;
	}

	/**
	 * 배송정보 상세조회
	 * @param model
	 * @param member
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET, value="/{deliver_seq}")
	public Model getDeliver(Model model,
							@PathVariable ("deliver_seq") String deliver_seq) {
		
		MemberVO.MemberDeliver vo = (MemberVO.MemberDeliver) service.getDeliver(deliver_seq);
		model.addAttribute("MODEL", vo);
		return model;
	}

	/**
	 * 배송정보 수정
	 * @param model
	 * @param member
	 * @return
	 */
	@RequestMapping(method = RequestMethod.PUT, value="/{deliver_seq}")
	public Model updateDeliver(Model model,
							@PathVariable ("deliver_seq") String deliver_seq,
							@RequestBody MemberVO.MemberDeliver deliverItem) {
		
		service.updateDeliver(deliverItem);
		return model;
	}

	/**
	 * 배송정보 삭제
	 * @param model
	 * @param member
	 * @return
	 */
	@RequestMapping(method = RequestMethod.DELETE, value="/{deliver_seq}")
	public Model deleteDeliver(Model model,
							@PathVariable ("deliver_seq") String deliver_seq) {
		
		service.deleteDeliver(deliver_seq);
		model.addAttribute("PROCESS_CODE", true);
		return model;
	}

	
}
